import { Random } from '@r-magician/utils';

const colors = ['#6F69AC', '#95DAC1', '#FFEBA1', '#FD6F96'];
const getColor = Random.getOneFactroy(colors);
const createDefaultImage = ({ w = 80, h = 80, fontSize = 30, text }) => {
  const color = getColor();
  const canvas = document.createElement('canvas');
  canvas.width = w;
  canvas.height = h;
  const ctx = canvas.getContext('2d');
  ctx.beginPath();
  ctx.fillStyle = color;
  ctx.rect(0, 0, w, h);
  ctx.fill();
  ctx.closePath();
  ctx.fillStyle = '#fff';
  ctx.font = `bold ${fontSize}px 微软雅黑`;
  ctx.textAlign = 'center'; // ctx.textBaseline = 'middle';
  ctx.fillText(text, w / 2, h / 2 + fontSize / 2);
  return canvas;
};

export default createDefaultImage;
